package com.yl.chainStore.entity.pay

import com.baomidou.mybatisplus.annotation.IdType
import com.baomidou.mybatisplus.annotation.TableField
import com.baomidou.mybatisplus.annotation.TableId
import com.baomidou.mybatisplus.annotation.TableName
import com.yl.chainStore.common.Constants
import com.yl.common.annotation.NoArg
import com.yl.common.getContext
import java.math.BigDecimal
import java.math.RoundingMode
import java.util.*

/**
 * <p>
 *  订单退款记录明细
 * </p>
 *
 * @author cxw
 * @since 2021-11-08
 */
@NoArg
@TableName("pay_order_detail_refund_log")
data class PayOrderDetailRefundLog(

	/**
	 * id
	 */
	@TableId(value = "id", type = IdType.AUTO)
	var id: Long,

	/**
	 * 明细id
	 */
	@TableField("detail_id")
	var detailId: Long,

	/**
	 * 退款单id（便于查询）
	 */
	@TableField("refund_order_id")
	var refundOrderId: Long,

	/**
	 * 数量
	 */
	@TableField("count")
	var count: Int,

	/**
	 * 退款金额（总）
	 */
	@TableField("refund_money")
	var refundMoney:Long,

	){

	/**
	 * 退款金额显示
	 */
	@TableField(exist = false)
	var refundMoneyShow: BigDecimal? = null
		get() {

			if (field == null) {
				return BigDecimal(refundMoney.div(Constants.OtherConfig.MONEY_TO_DB_DOUBLE)).setScale(
					2,
					RoundingMode.HALF_UP
				)
			}
			return field
		}
		set(value) {
			if (value != null) {
				refundMoney = (value.multiply(BigDecimal(Constants.OtherConfig.MONEY_TO_DB_DOUBLE))).toLong()
				field = value
			}
		}
}
